package com.elite.groovy.davco.clink;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.tinet.clink.cc.request.client.UnbindClientTelRequest;
import com.tinet.clink.cc.request.control.*;
import com.tinet.clink.cc.request.manage.OfflineClientRequest;
import com.tinet.clink.cc.response.client.UnbindClientTelResponse;
import com.tinet.clink.cc.response.control.*;
import com.tinet.clink.cc.response.manage.OfflineClientResponse;
import com.tinet.clink.core.client.Client;
import com.tinet.clink.core.exceptions.ClientException;
import com.tinet.clink.core.exceptions.ServerException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * 话务接口测试
 *
 * @author huwk
 * @date 2018/10/29
 **/
public class clinkCallControl extends AbstractInit {
    private static final Log log = LogFactory.getLog(clinkAgentStatus.class);

    private static ObjectMapper mapper = new ObjectMapper();

    // 上线
    public static String doOnline(Client client, String Cno, String BindTel) throws ServerException, ClientException, JsonProcessingException {
        log.debug("天润操作 上线-入参 Cno:" + Cno + "  BindTel:" + BindTel);

        OnlineRequest request = new OnlineRequest();
        request.setCno(Cno);
        request.setBindTel(BindTel);
        request.setBindType(1);
        request.setStatus(2);

        OnlineResponse response = client.getResponseModel(request);
        String clinkResult = mapper.writeValueAsString(response.getRequestId());
        log.debug("天润返回 上线-操作结果:" + clinkResult);

        return clinkResult;
    }

    // 下线
    public static String doOffline(Client client, String Cno) throws ServerException, ClientException, JsonProcessingException {
        log.debug("天润操作 下线-入参 Cno:" + Cno);

        OfflineRequest request = new OfflineRequest();
        request.setCno(Cno);
        request.setUnbindTel(1);

        OfflineResponse response = client.getResponseModel(request);
        String clinkResult = mapper.writeValueAsString(response.getRequestId());
        log.debug("天润返回 下线-操作结果:" + clinkResult);

        return clinkResult;
    }

    // 下线
    public String doOfflineClient(String Cno) throws ServerException, ClientException, JsonProcessingException {
        log.debug("天润操作 下线Client-入参 Cno:" + Cno);

        OfflineClientRequest request = new OfflineClientRequest();
        request.setCno(Cno);

        OfflineClientResponse response = client.getResponseModel(request);
        String clinkResult = mapper.writeValueAsString(response.getRequestId());
        log.debug("天润返回 下线Client-操作结果:" + clinkResult);

        return clinkResult;
    }

    // 外呼
    public static String doCallout(Client client, String Cno, String BindTel) throws ServerException, ClientException, JsonProcessingException {
        log.debug("天润操作 外呼-入参 Cno:" + Cno + " BindTel:" + BindTel);

        CalloutRequest request = new CalloutRequest();
        request.setCno(Cno);
        request.setCustomerNumber(BindTel);

        CalloutResponse response = client.getResponseModel(request);
        String clinkResult = mapper.writeValueAsString(response.getRequestId());
        log.debug("天润返回 外呼-操作结果:" + clinkResult);

        return clinkResult;
    }

    // 外呼取消
    public String doCalloutCancel(String Cno) throws ServerException, ClientException, JsonProcessingException {
        log.debug("天润操作 外呼取消-入参 Cno:" + Cno);

        CalloutCancelRequest request = new CalloutCancelRequest();
        request.setCno(Cno);

        CalloutCancelResponse response = client.getResponseModel(request);
        String clinkResult = mapper.writeValueAsString(response.getRequestId());
        log.debug("天润返回 外呼取消-操作结果:" + clinkResult);

        return clinkResult;
    }

    // 挂机
    public static String doUnlink(Client client, String Cno) throws ServerException, ClientException, JsonProcessingException {
        log.debug("天润操作 挂机-入参 Cno:" + Cno);

        UnlinkRequest request = new UnlinkRequest();
        request.setCno(Cno);

        UnlinkResponse response = client.getResponseModel(request);
        String clinkResult = mapper.writeValueAsString(response.getRequestId());
        log.debug("天润返回 挂机-操作结果:" + clinkResult);

        return clinkResult;
    }

    // 解绑
    public static String unbindClientTel(Client client, String Cno) throws ServerException, ClientException, JsonProcessingException {
        log.debug("天润操作 解绑-入参 Cno:" + Cno);
        UnbindClientTelRequest unbindClientTelRequest = new UnbindClientTelRequest();
        unbindClientTelRequest.setCno(Cno);
        UnbindClientTelResponse response = client.getResponseModel(unbindClientTelRequest);
        String clinkResult = mapper.writeValueAsString(response.getRequestId());
        log.debug("天润返回 解绑-操作结果:" + clinkResult);

        return clinkResult;
    }
}
